home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3157 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: longwood.cs.ucf.edu!not-for-mail
  2. From: stevens@longwood.cs.ucf.edu (John Stevens)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why use private class members instead of protected?
  5. Date: 22 Jan 1996 10:16:52 -0500
  6. Organization: University of Central Florida
  7. Message-ID: <4e09p4$sku@longwood.cs.ucf.edu>
  8. References: <30F4AB49.6ABB@sierra.net>
  9. NNTP-Posting-Host: longwood.cs.ucf.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. TGColwell (snowbull@sierra.net) wrote:
  13. : I'm relatively new to c++.  I have one quick question:  If child 
  14. : classes can only access protected members of the parent class, 
  15. : why make any members of any class private?  Wouldn't it be 
  16. : better to make members of the parent class protected so that the 
  17. : class is alway "inheritance ready"?
  18.  
  19. The short answer is that you may wish to encapsulate the implementation
  20. of your base class from your children, and enforce the derived classes
  21. use of access methods, etc. This is a design tradeoff (as usual) but
  22. consider what happens if I muck about with the protected internals of
  23. a base class in a dozen derived classes (even unto the 2nd and 3rd
  24. generations). Now I want to change the implementation of the base class.
  25. In the words of the immortal Astro: "Ruh-roh!". This is more common (at
  26. least in my commercial experience) than you might think, and it will
  27. burn you.
  28.  
  29. Any other comments?
  30.  
  31. My $.02.
  32. John S.
  33.  
  34.